<?php

class Truck_to_repair extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Truck_to_repair':
	 * @var integer $id
	 * @var string $reporter
	 * @var string $cause_of_accident
	 * @var integer $state
	 * @var string $create_time
	 */
	
	public $plate_no;
	public $reg_no;
	public $kind;
	private $_kind=array('0'=>'车辆','1'=>'尾板');
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'truck_to_repair';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('reporter','length','max'=>30),
			array('cause_of_accident','length','max'=>500),
			array('plate_no','length','max'=>10),
			array('reg_no','length','max'=>18),
			array('state', 'numerical', 'integerOnly'=>true),
			array('reporter,cause_of_accident,reg_no', 'required'),
			
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'fk_truck_id' =>'待修车辆id',
			'plate_no'=>'车牌号',
			'reg_no'=>'登记编号',
			'kind' =>'车辆/尾板',
			'reporter' => '申报人',
			'cause_of_accident' => '事故原因',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
	
	public function getKindName($n=null){
		return $this->_kind[$n==null?$this->kind:$n];
	}
	
	public function safeAttributes(){
		$params=parent::safeAttributes();
		$params[]='plate_no';
		$params[]='reg_no';
		return $params;
	}
}